package com.itsm.example.audit.pojo.dto;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.LinkedHashMap;

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
public class Result extends LinkedHashMap<String, Object> implements Serializable {

    public static final String SUCCESS = "success";//是否成功
    public static final String CODE = "code";//返回码
    public static final String MSG = "message" ;//返回信息
    public static final String DATA = "data"; //返回数据

    public Result(ResultCode resultCode) {
        super.put(SUCCESS,resultCode.success);
        super.put(CODE,resultCode.code);
        super.put(MSG,resultCode.msg());
    }

    public Result(ResultCode resultCode,Object data) {
        this(resultCode);
        super.put(DATA,data);
    }
    public Result(ResultCode resultCode,Object data, String msg) {
        this(resultCode,data);
        super.put(MSG,msg);
    }
    public Result(int code,String message,boolean success) {
        super.put(CODE, code);
        super.put(SUCCESS, success);
        super.put(MSG, message);
    }
    public Result(int code,String message,Object data,boolean success) {
        this(code, message, success);
        super.put(DATA, data);
    }


    public static Result success() {
        return new Result(ResultCode.SUCCESS);
    }
    public static Result success(Object data) {
        return new Result(ResultCode.SUCCESS,data);
    }
    public static Result success(Object data,String msg) {
        return new Result(ResultCode.SUCCESS,data,msg);
    }
    public static Result fail(){
        return new Result(ResultCode.FAIL);
    }
    public static Result fail(String message){
        return new Result(ResultCode.FAIL.code, message, ResultCode.FAIL.success);
    }
    public static Result fail(int code, String message){
        return new Result(code, message, ResultCode.FAIL.success);
    }

    public static Result error(){
        return new Result(ResultCode.SYS_ERR);
    }
    public static Result error(ResultCode code){
        return new Result(code);
    }

    public static Result error(String errorMsg){
        return new Result(ResultCode.SYS_ERR.code,errorMsg,ResultCode.SYS_ERR.success);
    }
    public static Result error(int code, String msg) {
        return new Result(code,msg,ResultCode.SYS_ERR.success);
    }




}
